#ifndef SERVER_H
#define SERVER_H

#include "NetworkDefinitions.h"
#include "NetworkMessage.h"
#include "NetworkBase.h"
#include "../Utility/Misc/Timer.h"
#include <vector>
using std::vector;

struct ClientInfo
{
	Address clientAddr;
	NetworkMessage msg;
	NetworkHeader header;

	ClientInfo(const Address& _address) : clientAddr(_address){}
};

class Server
{
private:
	typedef void (*MessageParserFunc)(NetworkMessage& _netMsg, Address& _incomingAddress);

	static Socket serverSocket;
	static vector<MessageParserFunc> msgParser;
	static vector<ClientInfo> clients;
	static Timer timer;
	static unsigned int maxClients;
	static NetworkHeader serverHeader;
	static float msgRate;
	static float msgTimer;
	static bool isRunning;

	static void ParseConnectMessage(NetworkMessage& _netMsg, Address& _incomingAddress);
	static void ParseDisconnectMessage(NetworkMessage& _netMsg, Address& _incomingAddress);
	static void ParseBroadcastMessage(NetworkMessage& _netMsg, Address& _incomingAddress);
	static void ParsePlayerMoveMessage(NetworkMessage& _netMsg, Address& _incomingAddress);

	static void SendMessages();
	static void LoadServerSettings(const char* const _filePath);
	static bool CheckSequence(NetworkMessage& _netMsg, Address& _sender);

public:
	static void Init();
	static void Update();
	static void Shutdown();

	static bool IsRunning() {return isRunning;}

};


#endif